import axios from "axios";
import { getToken } from "./token";
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

axios.defaults.baseURL = "http://127.0.0.1:8888/api/private/v1";

//请求拦截器
axios.interceptors.request.use(
  config => {
    //在发送请求前
    config.headers.Authorization = getToken();
    NProgress.start()
    return config;
  },
  error => {
    //请求错误
    return Promise.reject(error);
  }
);

//响应拦截器
// axios.interceptors.response.use(response => {
//   //响应数据
//   return response.data;
// });
axios.interceptors.response.use(config => {
  NProgress.done()
  return config
  })

export default axios; //直接返回axios;
